﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "教学运行管理 - 排课 - 教室课表");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		mathAdvice = getProperty("serviceFactory").getBean("senateMathAdvice");
		
		termId = event.getArg("TID");
		buildId = event.getArg("BID");
		clsroomId = event.getArg("CRID");
		
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");

		currentTab = event.getArg("TabID", "labCourseTable");

		clsroomArray = [];

		rs_clsroomData = queryNew("tasktime");

		targetArgs = structNew();
		
		if ( len(termId) ) {
		
			if ( len(clsroomId) ) {
				
				/* 单个教室课表 */
				tagCode = "JXCDKB-" & termId & "," & clsroomId;
				
				sql = "	SELECT
							cf.tasktime,cf.task_week,cf.task_id,cf.task_type
						FROM
							t_clsroom_forcourse cf INNER JOIN t_clsroom_timetable ct ON cf.crtime_id = ct.crtime_id
							INNER JOIN t_classroom c ON c.cr_id = ct.cr_id
						WHERE
							ct.term_id = :termId 
							AND
							c.cr_id = :clsroomId ";
				
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "clsroomId", value = clsroomId, cfsqltype = "cf_sql_char");
				queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
				rs_clsroomData = queryObj.execute(sql = sql).getResult();
				
				courseTables = [];
				
				for(a = 1; a lte rs_clsroomData.recordCount; a++){

					/* 载入教学任务 */
					switch(rs_clsroomData['task_type'][a]){
						case 'P':
							sql = "	SELECT
										c.course_name,t.tch_name
									FROM
										t_task tsk INNER JOIN t_teacher t ON t.tch_id = tsk.tch_id INNER JOIN t_course c ON c.cid = tsk.cid
									WHERE
										tsk.tsk_id = :taskId ";
							break;
						case 'R':
							sql = "	SELECT
										c.course_name,t.tch_name
									FROM
										t_reopen_task tsk INNER JOIN t_teacher t ON t.tch_id = tsk.tch_id INNER JOIN t_course c ON c.cid = tsk.cid
									WHERE
										tsk.tsk_id = :taskId ";
							break;
						case 'C':
							sql = "	SELECT
										c.course_name,t.tch_name
									FROM
										t_common_task tsk INNER JOIN t_teacher t ON t.tch_id = tsk.tch_id INNER JOIN t_course c ON c.cid = tsk.cid
									WHERE
										tsk.tsk_id = :taskId ";
							break;
						case 'T':
							sql = "	SELECT
										c.course_name,t.tch_name
									FROM
										t_sport_task tsk INNER JOIN t_teacher t ON t.tch_id = tsk.tch_id INNER JOIN t_course c ON c.cid = tsk.cid
									WHERE
										tsk.tsk_id = :taskId ";
							break;
					}
						
					queryObj = new Query(datasource = application.dnsSlave);
					queryObj.addParam(name = "taskId", value = rs_clsroomData['task_id'][a], cfsqltype = "cf_sql_varchar");
					rs_taskEntity = queryObj.execute(sql = sql).getResult();
					
					rowDate = [ rs_taskEntity.course_name, rs_clsroomData['tasktime'][a], '-', rs_clsroomData['task_week'][a], rs_taskEntity.tch_name ];
					arrayAppend(courseTables, rowDate);
					
				}
			
		
			}
		
			if ( len(buildId) ) {
			
				structInsert(targetArgs, "TID", termId);
				
				sql = "	SELECT
							b.b_id,b.b_name
						FROM
							t_building b
						WHERE
							b.b_id = :buildId ";
			
				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "buildId", value = buildId, cfsqltype = "cf_sql_char");
				rs_buildEntity = queryObj.execute(sql = sql).getResult();

				sql = "	SELECT
							c.cr_id,c.classroom,tct.cr_type_name,c.sits_course,c.cr_floor,
							SUM(ct.cellrelay) l_sum,
							SUM(CASE WHEN ct.wdidx = '1' THEN ct.cellrelay ELSE 0 END) w1_sum,
							SUM(CASE WHEN ct.wdidx = '2' THEN ct.cellrelay ELSE 0 END) w2_sum,
							SUM(CASE WHEN ct.wdidx = '3' THEN ct.cellrelay ELSE 0 END) w3_sum,
							SUM(CASE WHEN ct.wdidx = '4' THEN ct.cellrelay ELSE 0 END) w4_sum,
							SUM(CASE WHEN ct.wdidx = '5' THEN ct.cellrelay ELSE 0 END) w5_sum,
							SUM(CASE WHEN ct.wdidx = '6' THEN ct.cellrelay ELSE 0 END) w6_sum,
							SUM(CASE WHEN ct.wdidx = '7' THEN ct.cellrelay ELSE 0 END) w7_sum
						FROM
							t_clsroom_forcourse cf INNER JOIN t_clsroom_timetable ct ON cf.crtime_id = ct.crtime_id
							INNER JOIN t_classroom c ON ct.cr_id = c.cr_id INNER JOIN t_classroom_type tct ON tct.cr_type = c.cr_type
						WHERE
							c.b_id = :buildId 
							AND
							ct.term_id = :termId 
						GROUP BY
							c.cr_id,c.classroom,tct.cr_type_name,c.sits_course,c.cr_floor
						ORDER BY
							c.cr_floor,c.classroom";

				queryObj = new Query(datasource = application.dnsSlave);
				queryObj.addParam(name = "buildId", value = buildId, cfsqltype = "cf_sql_char");
				queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
				rs_clsroom = queryObj.execute(sql = sql).getResult();

			}
		
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('classroomArrange', targetArgs)#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学楼使用汇总</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 building"></i>学期教室课表
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
			
				<cfif len(termId) and len(clsroomId) and len(buildId)>
					
					<div class="UItab">
						<div class="tabLables">
							<span <cfif currentTab eq "labCourseTable">class="active"</cfif> id="labCourseTable" tabTarget="CourseTable">教室课表</span>
							<span <cfif currentTab eq "labClassroom">class="active"</cfif> id="labClassroom" tabTarget="Classroom">其他教室</span>
						</div>
					</div>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
						
							/* init Tab */
							$("div.tabContent[@id!=' + $targetID + ']").hide();
							$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
							$("div.tabLables > span").click(function(){
								var $targetID = $(this).attr("tabTarget");
							
								$("div.tabLables span").removeClass("active");
								$(this).addClass("active");
							
								$("div.tabContent[@id!=' + $targetID + ']").hide();
								$("div.tabContent#" + $targetID).show();
							});
						
						});
						// -->
						//]]>
					</script>
					
					<div id="CourseTable" class="tabContent">
						
						<div class="noticeBlock">
							<h3>教室课表</h3>
							<p>
								<span class="img icon16x16 message"></span>
								在<em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 教室需要承担课程安排如下.</p>
							<hr/>
						</div>
						
						<!-- courseTable -->
					<table class="UICourseTable">
						<thead>
							<tr>
								<td colspan="2" width="2%"></td>
								<td width="14%">星期一</td>
								<td width="14%">星期二</td>
								<td width="14%">星期三</td>
								<td width="14%">星期四</td>
								<td width="14%">星期五</td>
								<td width="14%">星期六</td>
								<td width="14%">星期天</td>
							</tr>
						</thead>
						<tbody>
							<cfloop from="1" to="6" index="lec">
								<tr>
									<cfswitch expression="#lec#">
										<cfcase value="1">
											<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
										</cfcase>
										<cfcase value="3">
											<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
										</cfcase>
										<cfcase value="5">
											<td rowspan="2"><cfoutput>#mathAdvice.convertLectureIdxToDayPart(lec)#</cfoutput></td>
										</cfcase>
									</cfswitch>
									<td><cfoutput>#mathAdvice.convertLectureIdxToChinese(lec)#</cfoutput></td>
									<cfloop from="1" to="7" index="wkday">
										<td>
											<cfloop array="#courseTables#" index="table">
                                                       
                                                       	<cfif table[2] eq wkday & "@" & lec & "-1">
													<div class="lecture">
														<!--- 节次 2 --->
														<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
														<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(1)</span><br/>
													</div>
												</cfif>

												<cfif table[2] eq wkday & "@" & lec & "-2">
													<div class="lecture">
														<!--- 节次 2 --->
														<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
														<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
													</div>
												</cfif>

												<cfif table[2] eq wkday & "@" & lec & "-3">
													<div class="lecture">
														<!--- 节次 3 --->
														<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
														<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(3)</span><br/>
													</div>
												</cfif>

												<cfif (table[2] eq wkday & "@" & lec & "-4") or (table[2] eq wkday & "@" & lec-1 & "-4")>
													<!--- 节次 4 --->
													<div class="lecture">
														<!--- 显示为节次 2 --->
														<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
														<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
													</div>
												</cfif>
												
												<cfif (table[2] eq wkday & "@" & lec & "-5")>
													<!--- 节次 5 --->
													<div class="lecture">
														<!--- 显示为节次 2 --->
														<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
														<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
													</div>
													<cfelseif (table[2] eq wkday & "@" & lec-1 & "-5")>
													<div class="lecture">
														<!--- 显示为节次 3 --->
														<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
														<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(3)</span><br/>
													</div>
												</cfif>
												
												<cfif (table[2] eq wkday & "@" & lec & "-8") or (table[2] eq wkday & "@" & lec-1 & "-8") or (table[2] eq wkday & "@" & lec-2 & "-8") or (table[2] eq wkday & "@" & lec-3 & "-8")>
													<!--- 节次 8 --->
													<div class="lecture">
														<!--- 显示为节次 2 --->
														<cfoutput>#table[1]#</cfoutput><cfif table[5] neq "-"> - <cfoutput>#table[5]#</cfoutput></cfif>
														<cfif table[3] neq "-"><br/><cfoutput>#table[3]#</cfoutput></cfif>
														<br/><span class="number"><cfoutput>#table[4]#</cfoutput>(2)</span><br/>
													</div>
												</cfif>
												
											</cfloop>
										</td>
									</cfloop>
								</tr>
							</cfloop>
						</tbody>
					</table>
					<!-- /courseTable -->
						
					</div>
					
					<div id="Classroom" class="tabContent">
						
						<cfif rs_buildEntity.recordCount>
							
							<cfset structInsert(targetArgs, "BID", rs_buildEntity.b_id, true ) />
							
							<div class="noticeBlock">
								<div class="operation">
									<a class="uiButton" target="_blank" href="<cfoutput>#buildURL('buildingCoursePrint', targetArgs)#</cfoutput>"><i class="mrs img btnPrint"></i><span class="uiButtonText">打印教学楼课表</span></a>
								</div>
								<h3><cfoutput>#rs_buildEntity.b_name#</cfoutput></h3>
								<p>
									<span class="img icon16x16 message"></span>
									<em><cfoutput>#academicYear#</cfoutput>-<cfoutput>#academicTerm#</cfoutput></em>学期, 
									安排了课程教学任务教室 <em><cfoutput>#rs_clsroom.recordCount#</cfoutput></em> 个
									.
								</p>
								<hr/>
							</div>
						</cfif>

						<cfif rs_clsroom.recordCount>
						
							<table class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td>教室</td>
										<td>类别</td>
										<td>排课座次</td>
										<td>楼层</td>
										<td>周学时</td>
										<td>一</td>
										<td>二</td>
										<td>三</td>
										<td>四</td>
										<td>五</td>
										<td>六</td>
										<td>日</td>
									</tr>
								</thead>
								<tbody>
									<cfset row = 0 />
                                    <cfloop query="rs_clsroom">
										<cfset row++ />
										<cfset structInsert(targetArgs, "CRID", rs_clsroom.cr_id, true) />
									
										<tr class="editRows">
											<td class="index"><cfoutput>#row#</cfoutput></td>
											<td><a href="<cfoutput>#buildURL('classroomCourseTable', targetArgs)#</cfoutput>"><cfoutput>#rs_clsroom.classroom#</cfoutput></a></td>
											<td><cfoutput>#rs_clsroom.cr_type_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.sits_course#</cfoutput></span></td>
											<td><cfoutput>#dictAdvice.getFloorString( rs_clsroom.cr_floor )#</cfoutput></td>
											<td><span class="numeric bold"><cfoutput>#rs_clsroom.l_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w1_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w2_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w3_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w4_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w5_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w6_sum#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_clsroom.w7_sum#</cfoutput></span></td>
										</tr>
									
									</cfloop>
								</tbody>
							</table>
						
						</cfif>
					
					</div>
					
				</cfif>
			
			</div>
		</li>
	</ul>
</div>





